package com.yn.pet.controller.app;


import com.yn.common.core.domain.AjaxResult;
import com.yn.pet.bus.entity.DeviceInfo;
import com.yn.pet.controller.pc.biz.DeviceInfoBizService;
import com.yn.pet.controller.pc.request.DeviceInfoUpdateRequest;
import com.yn.pet.controller.pc.request.PetQueryRequest;
import com.yn.pet.controller.pc.response.DeviceInfoBizResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * 设备信息表(DeviceInfo)表控制层
 *
 * @author makejava
 * @since 2025-07-09 12:00:46
 */
@RestController
@AllArgsConstructor
@RequestMapping("/front/deviceInfo")
@Api(tags = "app端——设备信息管理")
@Slf4j
public class ADeviceInfoController {
    private final DeviceInfoBizService deviceInfoBizService;

    /**
     * 用户端分页查询设备信息
     * @param request 查询参数
     * @return
     */
    @GetMapping("pageList")
    @ApiOperation("用户端分页查询设备信息")
    public AjaxResult APageList(PetQueryRequest request) {
        log.info("用户端分页查询设备信息入参，request:{}", request);
        return AjaxResult.success(deviceInfoBizService.userPageList(request));
    }


    @GetMapping("searchDeviceList")
    @ApiOperation("用户端搜索设备列表")
    public AjaxResult searchDeviceList(@RequestParam("keyword") @NotBlank String keyword) {
        log.info("用户端搜索设备列表入参，keyword:{}", keyword);
        return AjaxResult.success(deviceInfoBizService.searchDeviceList(keyword));
    }



    /**
     * 查询设备详情
     * @param deviceId 设备ID
     * @return 设备详情
     */
    @GetMapping("detail")
    @ApiOperation("查询设备详情")
    public AjaxResult queryById(@RequestParam("id") @NotNull Long deviceId) {
        log.info("查询设备详情入参 deviceId: {}", deviceId);
        return AjaxResult.success(deviceInfoBizService.queryById(deviceId));
    }

    /**
     * 设备基础信息
     * @param deviceId 设备ID
     * @return DeviceQueryResponse 设备基础信息
     */
    @GetMapping("basicInfo")
    @ApiOperation("查询设备基础信息")
    public AjaxResult basicInfo(@RequestParam("id") @NotNull Long deviceId) {
        log.info("查询设备基础信息入参：deviceId:{}",deviceId);
        return AjaxResult.success(deviceInfoBizService.basicInfo(deviceId));
    }

    /**
     * 设备首页设备基础信息
     * @param deviceId 设备ID
     * @return DeviceInfoBizResponse
     */
    @GetMapping("homeInfo")
    @ApiOperation("查询首页的设备基础信息")
    public AjaxResult homeInfo(@RequestParam("id") @NotNull Long deviceId) {
        log.info("查询首页的设备基础信息入参：deviceId:{}",deviceId);
        return AjaxResult.success(deviceInfoBizService.homeInfo(deviceId));
    }


    /**
     * 更新设备信息
     * @param request 设备信息请求对象
     * @return 无
     */
    @PostMapping("updateDeviceInfo")
    @ApiOperation("更新设备信息")
    public AjaxResult update(@RequestBody @Validated DeviceInfoUpdateRequest request) {
        log.info("更新设备信息入参：request:{}",request);
        deviceInfoBizService.updateDeviceInfo(request);
        return AjaxResult.success("更新成功");
    }

    /**
     * 更新宠物类型
     * @param deviceId  设备id
     * @param petType 宠物类型
     * @return
     */
    @GetMapping("updatePetType")
    @ApiOperation("设备详情页面更新宠物类型")
    public AjaxResult updatePetType(@RequestParam @NotNull Long deviceId,
                                    @RequestParam @NotNull Integer petType) {
        log.info("更新宠物类型入参：deviceId：{}, petType:{}", deviceId,petType);
        deviceInfoBizService.updatePetType(deviceId, petType);
        return AjaxResult.success("更新成功");
    }

    /**
     * 更新宠物类型
     * @param deviceId  设备id
     * @param petType 宠物类型
     * @return
     */
    @GetMapping("/home/updatePetType")
    @ApiOperation("首页更新宠物类型")
    public AjaxResult updatePetType2Home(@RequestParam @NotNull Long deviceId,
                                    @RequestParam @NotNull Integer petType) {
        deviceInfoBizService.updatePetType(deviceId, petType);
        return AjaxResult.success("更新成功");
    }


}

